package net.asfun.jvalog.vo;

import java.util.Date;

import net.asfun.jvalog.common.InteractException;
import net.asfun.jvalog.common.JdoerFactory;
import net.asfun.jvalog.entity.Message;
import net.asfun.jvalog.entity.Paper;
import net.asfun.jvalog.util.InputFilter;

public class Comment{
	
	private Message msg;
	
	private Paper po;

	public Comment(Message message) {
		if ( message == null ) {
			throw new InteractException("Comment not found");
		}
		this.msg = message;
	}
	
	public Long getId() {
		return msg.getKey().getId();
	}
	
	public String getUserName() {
		return msg.getUserName();
	}
	
	public String getWebUrl() {
		//TODO member.url
		return "http://blog.asfun.net";
	}
	
	public String getEmail() {
		return msg.getEmail();
	}
	
	public String getContent() {
		String content = msg.getContent().getValue();
		return content;
	}
	
	public String getText() {
		String content = msg.getContent().getValue();
		return InputFilter.pureText(content);
	}
	
	public Date getDate() {
		return msg.getDate();
	}
	
	public boolean isPublished() {
		if (msg == null) return false;
		return msg.isPublished();
	}
	
	public Long getPostId() {
		return msg.getPaper().getId();
	}
	
	public Post getPost() {
		setPost();
		return new Post(po);
	}
	
	private void setPost() {
		if ( po == null ) {
			po = JdoerFactory.jdoPaper.load(msg.getPaper().getId());
		}
	}

}
